package com.test.daily.leetcode.y2022.m06.day0611.v02;

/**
 * Solution
 *
 * @author Tom on 2022/6/11
 */
public class Solution {
    public int minFlipsMonoIncr(String s) {
        int N = s.length();
        int[] P = new int[N+1];
        for (int i = 0; i < N; i++) {
            P[i+1] = P[i] + (s.charAt(i) == '1' ? 1:0);
        }
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < N + 1; i++){
            min = Math.min(min, P[i] + N -i - (P[N]- P[i]));
        }
        return min;
    }
}
